package com.duobaoyu.dby.supply.admin.controller.config;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.common.core.validator.groups.Add;
import com.duobaoyu.dby.common.core.validator.groups.Edit;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.biz.client.resource.ResourceDictionaryAdminClient;
import com.duobaoyu.dby.supply.biz.client.resource.bean.dto.DictionaryDTO;
import com.duobaoyu.dby.supply.biz.client.resource.bean.vo.DictionaryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 字典管理
 * @className: DictionaryController
 * @description: 字典表
 * @author: lyy
 * @createDate: 2022-06-23 9:33
 * @Version: 1.0
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/dictionary")
@Api(value = "dictionary", tags = "字典表")
public class DictionaryController {

	private final ResourceDictionaryAdminClient resourceDictionaryAdminClient;

	/**
	 * 查询字典列表
	 * @param dictionary
	 * @return
	 */
	@GetMapping
	@ApiOperation(value = "查询字典列表", notes = "查询字典列表")
	@SupplySysLog(value = "查询字典列表",operationType = OperationTypeEnum.SELECT)
	public R<Page<DictionaryVO>> queryPage(DictionaryDTO dictionary) {

		return R.ok(resourceDictionaryAdminClient.queryPage(dictionary));
	}

	/**
	 * 新增字典表
	 * @param dictionary
	 * @return
	 */
	@PostMapping
	@ApiOperation(value = "新增字典表", notes = "新增字典表")
	@SupplySysLog(value = "新增字典表",operationType = OperationTypeEnum.INTERT)
	public R<Long> save(@RequestBody @Validated(value = Add.class) DictionaryDTO dictionary) {

		return R.ok(resourceDictionaryAdminClient.saveDictionary(dictionary));
	}

	/**
	 * 修改字典表
	 * @param dictionary
	 * @return
	 */
	@PutMapping
	@ApiOperation(value = "修改字典表", notes = "修改字典表")
	@SupplySysLog(value = "修改字典表",operationType = OperationTypeEnum.UPDATE)
	public R<Boolean> modify(@RequestBody @Validated(value = Edit.class) DictionaryDTO dictionary) {

		return R.ok(resourceDictionaryAdminClient.updateDictionary(dictionary));
	}

	/**
	 * 删除字典表
	 * @param dictionaryIds
	 * @return
	 */
	@DeleteMapping
	@ApiOperation(value = "删除字典表", notes = "删除字典表")
	@SupplySysLog(value = "删除字典表",operationType = OperationTypeEnum.DELETE)
	public R<Boolean> remove(@RequestBody @Validated List<Long> dictionaryIds) {

		return R.ok(resourceDictionaryAdminClient.removeDictionaryByIds(dictionaryIds));
	}
}
